package catchData;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.log4j.Logger;

import util.CatchDataUtil;

/**
 * @author suwy
 * @date 2014-2-18
 * @todo TODO
 */
public class CatchYaozhi2 {
	
	private static final Logger LOG = Logger.getLogger(CatchYaozhi2.class);
	private String webURL = "http://db.yaozh.com/duizhaopin/";
	private String htmFolder = "I:/data/新康界抓取数据/download/中检所标准品查询2";
	private int[] pageNum = {
			1,
			2,
			3,
			4,
			6,
			7,
			8,
			9,
			10,
			11,
			12,
			13,
			14,
			15,
			16,
			17,
			18,
			19,
			20,
			21,
			22,
			23,
			24,
			25,
			26,
			27,
			28,
			29,
			34,
			35,
			36,
			37,
			38,
			39,
			40,
			41,
			42,
			43,
			44,
			45,
			46,
			50,
			51,
			52,
			54,
			55,
			56,
			57,
			58,
			59,
			60,
			61,
			62,
			63,
			65,
			66,
			67,
			68,
			69,
			70,
			71,
			72,
			73,
			74,
			75,
			76,
			77,
			78,
			79,
			80,
			81,
			82,
			83,
			84,
			85,
			86,
			87,
			88,
			89,
			90,
			91,
			92,
			93,
			94,
			95,
			96,
			97,
			98,
			99,
			100,
			101,
			102,
			103,
			104,
			105,
			106,
			107,
			108,
			109,
			110,
			111,
			112,
			113,
			114,
			115,
			116,
			117,
			118,
			119,
			120,
			121,
			122,
			123,
			124,
			125,
			126,
			127,
			128,
			129,
			130,
			131,
			132,
			133,
			134,
			135,
			136,
			137,
			138,
			139,
			140,
			141,
			142,
			143,
			144,
			145,
			146,
			147,
			148,
			149,
			150,
			151,
			152,
			153,
			154,
			155,
			156,
			157,
			158,
			159,
			160,
			161,
			162,
			163,
			164,
			165,
			166,
			167,
			168,
			169,
			170,
			171,
			172,
			173,
			174,
			175,
			176,
			177,
			178,
			179,
			180,
			181,
			182,
			183,
			184,
			185,
			186,
			187,
			188,
			189,
			190,
			191,
			192,
			193,
			194,
			195,
			196,
			197,
			198,
			199,
			200,
			201,
			202,
			203,
			204,
			205,
			206,
			207,
			208,
			209,
			210,
			211,
			212,
			213,
			214,
			215,
			216,
			217,
			218,
			219,
			220,
			221,
			222,
			223,
			224,
			225,
			226,
			227,
			228,
			229,
			230,
			231,
			232,
			233,
			234,
			235,
			236,
			237,
			238,
			239,
			240,
			241,
			242,
			243,
			244,
			245,
			246,
			247,
			248,
			249,
			250,
			251,
			252,
			253,
			254,
			255,
			256,
			257,
			258,
			259,
			260,
			261,
			262,
			263,
			264,
			265,
			266,
			267,
			268,
			269,
			270,
			271,
			272,
			273,
			274,
			275,
			276,
			277,
			278,
			279,
			280,
			281,
			282,
			283,
			284,
			285,
			286,
			287,
			288,
			289,
			290,
			291,
			292,
			293,
			294,
			295,
			296,
			297,
			298,
			299,
			300,
			301,
			302,
			303,
			304,
			305,
			306,
			307,
			308,
			309,
			310,
			311,
			312,
			313,
			314,
			315,
			316,
			317,
			318,
			319,
			320,
			321,
			322,
			323,
			324,
			325,
			326,
			327,
			328,
			329,
			330,
			331,
			332,
			333,
			334,
			335,
			336,
			337,
			338,
			339,
			340,
			341,
			342,
			343,
			344,
			345,
			346,
			347,
			348,
			349,
			350,
			351,
			352,
			353,
			354,
			355,
			356,
			357,
			358,
			359,
			360,
			361,
			362,
			363,
			364,
			365,
			366,
			367,
			368,
			369,
			370,
			371,
			372,
			373,
			374,
			375,
			376,
			377,
			378,
			379,
			380,
			381,
			382,
			383,
			384,
			385,
			386,
			387,
			388,
			389,
			390,
			391,
			392,
			393,
			394,
			395,
			396,
			397,
			398,
			399,
			400,
			401,
			402,
			403,
			404,
			405,
			406,
			407,
			408,
			409,
			410,
			411,
			412,
			413,
			414,
			415,
			416,
			417,
			418,
			419,
			420,
			421,
			422,
			423,
			424,
			425,
			426,
			427,
			428,
			429,
			430,
			431,
			432,
			433,
			434,
			435,
			436,
			437,
			438,
			439,
			440,
			441,
			442,
			443,
			444,
			445,
			446,
			447,
			448,
			449,
			450,
			451,
			452,
			453,
			454,
			455,
			456,
			457,
			458,
			459,
			460,
			461,
			462,
			463,
			464,
			465,
			466,
			467,
			468,
			469,
			470,
			471,
			472,
			473,
			474,
			475,
			476,
			477,
			478,
			479,
			480,
			481,
			482,
			483,
			484,
			485,
			486,
			487,
			488,
			489,
			490,
			491,
			492,
			493,
			494,
			495,
			496,
			497,
			498,
			499,
			500,
			501,
			502,
			503,
			504,
			505,
			506,
			507,
			508,
			509,
			510,
			511,
			512,
			513,
			514,
			515,
			516,
			517,
			518,
			519,
			520,
			521,
			522,
			523,
			524,
			525,
			526,
			527,
			528,
			529,
			530,
			531,
			532,
			533,
			534,
			535,
			536,
			537,
			538,
			539,
			540,
			541,
			542,
			543,
			544,
			545,
			546,
			547,
			548,
			549,
			550,
			551,
			552,
			553,
			554,
			555,
			556,
			557,
			558,
			559,
			560,
			561,
			562,
			563,
			564,
			565,
			566,
			567,
			568,
			569,
			570,
			571,
			572,
			573,
			574,
			575,
			576,
			577,
			578,
			579,
			580,
			581,
			582,
			583,
			584,
			585,
			586,
			587,
			588,
			589,
			590,
			591,
			592,
			593,
			594,
			595,
			596,
			597,
			598,
			599,
			600,
			601,
			602,
			603,
			604,
			605,
			606,
			607,
			608,
			609,
			610,
			611,
			612,
			613,
			614,
			615,
			616,
			617,
			618,
			619,
			620,
			621,
			622,
			623,
			624,
			625,
			626,
			627,
			628,
			629,
			630,
			631,
			632,
			633,
			634,
			635,
			636,
			637,
			638,
			639,
			640,
			641,
			642,
			643,
			644,
			645,
			646,
			647,
			648,
			649,
			650,
			651,
			652,
			653,
			654,
			655,
			656,
			657,
			658,
			659,
			660,
			661,
			662,
			663,
			664,
			665,
			666,
			667,
			668,
			669,
			670,
			671,
			672,
			673,
			674,
			675,
			676,
			677,
			678,
			679,
			680,
			681,
			682,
			683,
			684,
			685,
			686,
			687,
			688,
			689,
			690,
			704,
			705,
			706,
			707,
			708,
			709,
			711,
			714,
			13024,
			13025,
			13026,
			13027,
			13028,
			13029,
			13030,
			13031,
			13032,
			13033,
			13034,
			13035,
			13036,
			13037,
			13038,
			13039,
			13040,
			13041,
			13042,
			13043,
			13044,
			13045,
			13046,
			13047,
			13048,
			13049,
			13050,
			13051,
			13052,
			13053,
			13054,
			13055,
			13056,
			13057,
			13058,
			13059,
			13060,
			13061,
			13062,
			13063,
			13064,
			13065,
			13066,
			13067,
			13068,
			13069,
			13070,
			13071,
			13072,
			13073,
			13074,
			13075,
			13076,
			13077,
			13078,
			13079,
			13080,
			13081,
			13082,
			13083,
			13084,
			13085,
			13086,
			13087,
			13088,
			13089,
			13090,
			13091,
			13092,
			13093,
			13094,
			13095,
			13096,
			13097,
			13098,
			13099,
			13100,
			13101,
			13102,
			13103,
			13104,
			13105,
			13106,
			13107,
			13108,
			13109,
			13110,
			13111,
			13112,
			13113,
			13114,
			13115,
			13116,
			13117,
			13118,
			13119,
			13120,
			13121,
			13122,
			13123,
			13124,
			13125,
			13126,
			13127,
			13128,
			13129,
			13130,
			13131,
			13132,
			13133,
			13134,
			13135,
			13136,
			13137,
			13138,
			13139,
			13140,
			13141,
			13142,
			13143,
			13144,
			13145,
			13146,
			13147,
			13148,
			13149,
			13150,
			13151,
			13152,
			13153,
			13154,
			13155,
			13156,
			13157,
			13158,
			13159,
			13160,
			13161,
			13162,
			13163,
			13164,
			13165,
			13166,
			13167,
			13168,
			13169,
			13170,
			13171,
			13172,
			13173,
			13174,
			13175,
			13176,
			13177,
			13178,
			13179,
			13180,
			13181,
			13182,
			13183,
			13184,
			13185,
			13186,
			13187,
			13188,
			13189,
			13190,
			13191,
			13192,
			13193,
			13194,
			13195,
			13196,
			13197,
			13198,
			13199,
			13200,
			13201,
			13202,
			13203,
			13204,
			13205,
			13206,
			13207,
			13208,
			13209,
			13210,
			13211,
			13212,
			13213,
			13214,
			13215,
			13216,
			13217,
			13218,
			13219,
			13220,
			13221,
			13222,
			13223,
			13224,
			13225,
			13226,
			13227,
			13228,
			13229,
			13230,
			13231,
			13232,
			13233,
			13234,
			13235,
			13236,
			13237,
			13238,
			13239,
			13240,
			13241,
			13242,
			13243,
			13244,
			13245,
			13246,
			13247,
			13248,
			13249,
			13250,
			13251,
			13252,
			13253,
			13254,
			13255,
			13256,
			13257,
			13258,
			13259,
			13260,
			13261,
			13262,
			13263,
			13264,
			13265,
			13266,
			13267,
			13268,
			13269,
			13270,
			13271,
			13272,
			13273,
			13274,
			13275,
			13276,
			13277,
			13278,
			13279,
			13280,
			13281,
			13282,
			13283,
			13284,
			13285,
			13286,
			13287,
			13288,
			13289,
			13290,
			13291,
			13292,
			13293,
			13294,
			13295,
			13296,
			13297,
			13298,
			13299,
			13300,
			13301,
			13302,
			13303,
			13304,
			13305,
			13306,
			13307,
			13308,
			13309,
			13310,
			13311,
			13312,
			13313,
			13314,
			13315,
			13316,
			13317,
			13318,
			13319,
			13320,
			13321,
			13322,
			13323,
			13324,
			13325,
			13326,
			13327,
			13328,
			13329,
			13330,
			13331,
			13332,
			13333,
			13334,
			13335,
			13336,
			13337,
			13338,
			13339,
			13340,
			13341,
			13342,
			13343,
			13344,
			13345,
			13346,
			13347,
			13348,
			13349,
			13350,
			13351,
			13352,
			13353,
			13354,
			13355,
			13356,
			13357,
			13358,
			13359,
			13360,
			13361,
			13362,
			13363,
			13364,
			13365,
			13366,
			13367,
			13368,
			13369,
			13370,
			13371,
			13372,
			13373,
			13374,
			13375,
			13376,
			13377,
			13378,
			13379,
			13380,
			13381,
			13382,
			13383,
			13384,
			13385,
			13386,
			13387,
			13388,
			13389,
			13390,
			13391,
			13392,
			13393,
			13394,
			13395,
			13396,
			13397,
			13398,
			13399,
			13400,
			13401,
			13402,
			13403,
			13404,
			13405,
			13406,
			13407,
			13408,
			13409,
			13410,
			13411,
			13412,
			13413,
			13414,
			13415,
			13416,
			13417,
			13418,
			13419,
			13420,
			13421,
			13422,
			13423,
			13424,
			13425,
			13426,
			13427,
			13428,
			13429,
			13430,
			13431,
			13432,
			13433,
			13434,
			13435,
			13436,
			13437,
			13438,
			13439,
			13440,
			13441,
			13442,
			13443,
			13444,
			13445,
			13446,
			13447,
			13448,
			13449,
			13450,
			13451,
			13452,
			13453,
			13454,
			13455,
			13456,
			13457,
			13458,
			13459,
			13460,
			13461,
			13462,
			13463,
			13464,
			13465,
			33955,
			33956,
			33957,
			33958,
			33959,
			33960,
			33961,
			33962,
			33963,
			33964,
			33965,
			33966,
			33967,
			33968,
			33969,
			33970,
			33971,
			33972,
			33973,
			33974,
			33975,
			33976,
			33977,
			33978,
			33979,
			33980,
			33981,
			33982,
			33983,
			33984,
			33985,
			33986,
			33987,
			33988,
			33989,
			33990,
			33991,
			33992,
			33993,
			33994,
			33995,
			33996,
			33997,
			33998,
			33999,
			34000,
			34001,
			34002,
			34003,
			34004,
			34005,
			34006,
			34007,
			34008,
			34009,
			34010,
			34011,
			34012,
			34013,
			34014,
			34015,
			34016,
			34017,
			34018,
			34019,
			34020,
			34021,
			34022,
			34023,
			34024,
			34025,
			34026,
			34027,
			34028,
			34029,
			34030,
			34031,
			34032,
			34033,
			34034,
			34035,
			34036,
			34037,
			34038,
			34039,
			34040,
			34041,
			34042,
			34043,
			34044,
			34045,
			34046,
			34047,
			34048,
			34049,
			34050,
			34051,
			34052,
			34053,
			34054,
			34055,
			34056,
			34057,
			34058,
			34059,
			34060,
			34061,
			34062,
			34063,
			34064,
			34065,
			34066,
			34067,
			34068,
			34069,
			34070,
			34071,
			34072,
			34073,
			34074,
			34075,
			34076,
			34077,
			34078,
			34079,
			34080,
			34081,
			34082,
			34083,
			34084,
			34085,
			34086,
			34087,
			34088,
			34089,
			34090,
			34091,
			34092,
			34093,
			34094,
			34095,
			34096,
			34097,
			34098,
			34099,
			34100,
			34101,
			34102,
			34103,
			34104,
			34105,
			34106,
			34107,
			34108,
			34109,
			34110,
			34111,
			34112,
			34113,
			34114,
			34115,
			34116,
			34117,
			34118,
			34119,
			34120,
			34121,
			34122,
			34123,
			34124,
			34125,
			34126,
			34127,
			34128,
			34129,
			34130,
			34131,
			34132,
			34133,
			34134,
			34135,
			34136,
			34137,
			34138,
			34139,
			34140,
			34141,
			34142,
			34143,
			34144,
			34145,
			34146,
			34147,
			34148,
			34149,
			34150,
			34151,
			34152,
			34153,
			34154,
			34155,
			34156,
			34157,
			34158,
			34159,
			34160,
			34161,
			34162,
			34163,
			34164,
			34165,
			34166,
			34167,
			34168,
			34169,
			34170,
			34171,
			34172,
			34173,
			34174,
			34175,
			34176,
			34177,
			34178,
			34179,
			34180,
			34181,
			34182,
			34183,
			34184,
			34185,
			34186,
			34187,
			34188,
			34189,
			34190,
			34191,
			34192,
			34193,
			34194,
			34195,
			34196,
			34197,
			34198,
			34199,
			34200,
			34201,
			34202,
			34203,
			34204,
			34205,
			34206,
			34207,
			34208,
			34209,
			34210,
			34211,
			34212,
			34213,
			34214,
			34215,
			34216,
			34217,
			34218,
			34219,
			34220,
			34221,
			34222,
			34223,
			34224,
			34225,
			34226,
			34227,
			34228,
			34229,
			34230,
			34231,
			34232,
			34233,
			34234,
			34235,
			34236,
			34237,
			34238,
			34239,
			34240,
			34241,
			34242,
			34243,
			34244,
			34245,
			34246,
			34247,
			34248,
			34249,
			34250,
			34251,
			34252,
			34253,
			34254,
			34255,
			34256,
			34257,
			34258,
			34259,
			34260,
			34261,
			34262,
			34263,
			34264,
			34265,
			34266,
			34267,
			34268,
			34269,
			34270,
			34271,
			34272,
			34273,
			34274,
			34275,
			34276,
			34277,
			34278,
			34279,
			34280,
			34281,
			34282,
			34283,
			34284,
			34285,
			34286,
			34287,
			34288,
			34289,
			34290,
			34291,
			34292,
			34293,
			34294,
			34295,
			34296,
			34297,
			34298,
			34299,
			34300,
			34301,
			34302,
			34303,
			34304,
			34305,
			34306,
			34307,
			34308,
			34309,
			34310,
			34311,
			34312,
			34313,
			34314,
			34315,
			34316,
			34317,
			34318,
			34319,
			34320,
			34321,
			34322,
			34323,
			34324
	};
	
	private void excute() {
		HttpClient client = CatchDataUtil.initHttpClient();
		PostMethod postMethod = null;
		StringBuilder stringBuilder = new StringBuilder();
		try {
			for(int i = 0; i < pageNum[i]; i++) {
				postMethod = new PostMethod(webURL + pageNum[i] + ".html");
				CatchDataUtil.setHeaders(postMethod, webURL + pageNum[i] + ".html",
						CatchDataUtil.getWebSite(webURL));
				client.executeMethod(postMethod);
				stringBuilder.append(postMethod.getResponseBodyAsString());
				LOG.info(webURL + pageNum[i] + ".html");
				CatchDataUtil.saveDataFile(htmFolder, stringBuilder.toString(), i+1, "utf-8");
				postMethod.releaseConnection();
				stringBuilder.delete(0, stringBuilder.length());
			}
		} catch (Exception e) {
			LOG.info(e);
		} finally {
			postMethod.releaseConnection();
		}
	}
	
	public static void main(String[] args) {
		CatchYaozhi2 instance = new CatchYaozhi2();
		instance.excute();
	}
}